package io.renren.modules.forYoung.controller;

import java.util.Arrays;
import java.util.Map;

import io.renren.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.forYoung.entity.ForYounyEntity;
import io.renren.modules.forYoung.service.ForYounyService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 
 *
 * @author xuebing
 * @email xuebinggod@163.com
 * @date 2018-10-25 19:29:43
 */
@RestController
@RequestMapping("forYoung/foryouny")
public class ForYounyController {
    @Autowired
    private ForYounyService forYounyService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("forYoung:foryouny:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = forYounyService.queryPage(params);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("forYoung:foryouny:info")
    public R info(@PathVariable("id") Integer id){
        ForYounyEntity forYouny = forYounyService.selectById(id);

        return R.ok().put("forYouny", forYouny);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("forYoung:foryouny:save")
    public R save(@RequestBody ForYounyEntity forYouny){
        forYounyService.insert(forYouny);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("forYoung:foryouny:update")
    public R update(@RequestBody ForYounyEntity forYouny){
        ValidatorUtils.validateEntity(forYouny);
        forYounyService.updateAllColumnById(forYouny);//全部更新
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("forYoung:foryouny:delete")
    public R delete(@RequestBody Integer[] ids){
        forYounyService.deleteBatchIds(Arrays.asList(ids));

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/del")
    @RequiresPermissions("forYoung:foryouny:delete")
    public R del(@RequestBody ForYounyEntity f){
        forYounyService.updateById(f);

        return R.ok();
    }

}
